﻿#ifndef VIDEOITEM_H
#define VIDEOITEM_H

#include <QQuickItem>
#include <QSGSimpleTextureNode>
#include <QImage>
#include <QMutex>
#include <QSharedPointer>

class VideoItem : public QQuickItem
{
    Q_OBJECT
    Q_PROPERTY(QImage frame READ frame WRITE setFrame NOTIFY frameChanged)

public:
    VideoItem(QQuickItem *parent = nullptr);
    ~VideoItem();

    QImage frame() const;
    void setFrame(const QImage &frame);

signals:
    void frameChanged();
    void frameProcessed();

protected:
    QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override;

private:
    mutable QMutex m_frameMutex;
    QSharedPointer<QImage> m_currentFrame;
    QSGTexture *m_lastTexture = nullptr;
};

#endif // VIDEOITEM_H
